/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var fetchProperties = require("../constant/fetchProperties");
	var gridEvents = require("../handler/gridEvents");
	
    var instance = {
        initComponent: function (params, widget) {
        	var roomPerGrid = new Grid({
        	    parentNode: ".J-editgrid",
        	    autoRender: false,
        	    model: {
        	        url: "api/roompersonalInfo/query",
        	        params: function() {
        	            return {
        	            	pkRoomPersonalInfoIn:widget.get("pkRoomPerList"),
        	            	"fetchProperties": "*"//fetchProperties.grid
        	            };
        	        },
        	        columns: [{
        	            name: "signUpRegister.personalInfo.name",
        	            label: "姓名",
        	            format: function(value,row){
        	            	if(widget.memDataSource){
        	            		return row.signUpRegister.personalInfo.name;
        	            	}else{
        	            		return row.nonMemberRegister.signUpRegister.personalInfo.name;
        	            	}
        	            }
        	        }, {
        	            name: "signUpRegister.personalInfo.idNumber",
        	            label: "身份证号",
        	            format: function(value,row){
        	            	if(widget.memDataSource){
        	            		return row.signUpRegister.personalInfo.idNumber;
        	            	}else{
        	            		return row.nonMemberRegister.signUpRegister.personalInfo.idNumber;
        	            	}
        	            }
        	        }, {
        	            name: "signUpRegister.personalInfo.sex.value",
        	            label: "性别",
        	            format: function(value,row){
        	            	if(widget.memDataSource){
        	            		return row.signUpRegister.personalInfo.sex ? 
        	            				row.signUpRegister.personalInfo.sex.value : "男";
        	            	}else{
        	            		return row.nonMemberRegister.signUpRegister.personalInfo.sex ?
        	            				row.nonMemberRegister.signUpRegister.personalInfo.sex.value : "男";
        	            	}
        	            }
        	        }, {
        	            name: "signUpRegister.personalInfo.mobilePhone",
        	            label: "手机号",
        	            format: function(value,row){
        	            	if(widget.memDataSource){
        	            		return row.signUpRegister.personalInfo.mobilePhone 
        	            		? row.signUpRegister.personalInfo.mobilePhone : "";
        	            	}else{
        	            		return row.nonMemberRegister.signUpRegister.personalInfo.mobilePhone 
        	            		? row.nonMemberRegister.signUpRegister.personalInfo.mobilePhone : "";
        	            	}
        	            }
        	        }, {
        	            name: "signUpRegister.checkOutDate",
        	            label: "退住日期",
        	            format: function(value,row){
        	            	if(widget.memDataSource){
        	            		if(value){
        	            			return moment(row.signUpRegister.checkOutDate).format("YYYY-MM-DD");
        	            		}
        	            	}else{
        	            		if(row.nonMemberRegister.signUpRegister.checkOutDate){
        	            			return moment(row.nonMemberRegister.signUpRegister.checkOutDate).format("YYYY-MM-DD");
        	            		}
        	            	}
	            			return "";
        	            },
        	        }, {
        	            name: "roomConsumption",
        	            label: "房内消费（元）",
        	            format: function(value, row){
    	            		return parseFloat(value).toFixed(2);
        	            }
        	        }, {
        	            name: "damagesConsumption",
        	            label: "赔偿费（元）",
        	            format: function(value, row){
    	            		return parseFloat(value).toFixed(2);
        	            }
        	        }, {
        	            name: "signUpRegister.checkOut",
        	            label: "状态",
        	            format: function(value,row){
        	            	if(widget.memDataSource){
        	            		if(value){
            	            		return "已确认";
            	            	}else{
            	            		return "待确认";
            	            	}
        	            	}else{
        	            		if(row.nonMemberRegister.signUpRegister.checkOut){
        	            			return "已确认";
        	            		}else{
        	            			return "待确认";
        	            		}
        	            	}
        	            }
        	        }, {
        	            name: "operate",
        	            label: "操作",
        	            format: "button",
        	            formatparams: [{
        	                id: "confirm",
        	                text: "确认",
        	                show:function(index, data, rowEL){
        	                	if(widget.memDataSource){
        	                		if(data.signUpRegister.checkOut || widget.detail){
        	                			return false;
        	                		}else{
        	                			return true
        	                		}
        	                	}else{
        	                		if(data.nonMemberRegister.signUpRegister.checkOut || widget.detail){
        	                			return false;
        	                		}else{
        	                			return true
        	                		}
        	                	}
        	                },
        	                handler: function(index, data, rowEL) {
        	                	gridEvents.confirmData(widget,data.pkRoomPersonalInfo);
        	                }
        	            }, {
        	                id: "inputConsumption",
        	                text: "录入消费",
        	                show:function(index, data, rowEL){
        	                	if(widget.memDataSource){
        	                		if(data.signUpRegister.checkOut || widget.detail){
        	                			return false;
        	                		}else{
        	                			return true
        	                		}
        	                	}else{
        	                		if(data.nonMemberRegister.signUpRegister.checkOut || widget.detail){
        	                			return false;
        	                		}else{
        	                			return true
        	                		}
        	                	}
        	                },
        	                handler: function(index, data, rowEL) {
        	                	gridEvents.consumption(data,widget,true);
        	                }
        	            }, {
        	                id: "detail",
        	                text: "详情",
        	                show:function(index, data, rowEL){
        	                	if(widget.memDataSource){
        	                		if(data.signUpRegister.checkOut){
        	                			return true
        	                		}else{
        	                			return false;
        	                		}
        	                	}else{
        	                		if(data.nonMemberRegister.signUpRegister.checkOut){
        	                			return true
        	                		}else{
        	                			return false;
        	                		}
        	                	}
        	                },
        	                handler: function(index, data, rowEL) {
        	                	gridEvents.consumption(data,widget,false);
        	                }
        	            }]
        	        }]
        	    }
        	});
        	widget.set("roomPerGrid",roomPerGrid);
        }
    };
    module.exports = instance;
});
